package com.crayfish.quduo.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;

import com.crayfish.quduo.App;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by crayfish on 2016/11/24.
 * MVP 基类
 */
public abstract class BaseMvpActivity<T extends BasePresenter> extends BaseActivity implements BaseView{

    protected T mPresenter;

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        initPresenter();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        initPresenter();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        initPresenter();
    }

    private void initPresenter(){
        mPresenter = createPresenter();
        if(mPresenter != null){
            mPresenter.attachView(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter != null){
            mPresenter.detachView();
        }
    }
    protected abstract T createPresenter();
}
